#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc, char* argv[])
{
    std::cout << "argv[1], 原始文件路径名称\n";
    std::cout << "argv[2], 压缩文件名\n";
    if(argc < 3)
    {
        std::cout << "参数个数有误\n";
        return -1;
    }

    std::string ifilename = argv[1];
    std::string ofilename = argv[2];

    std::ifstream ifs;
    ifs.open(ifilename, std::ios::binary);
    ifs.seekg(0, std::ios::end);//偏移到末尾
    size_t fsize = ifs.tellg();///获取末尾偏移量--文件长度
    ifs.seekg(0, std::ios::beg);
    std::string body;
    body.resize(fsize);
    ifs.read(&body[0], fsize);//读取原始文件内容到body中

    //开始压缩
    std::string packed = bundle::pack(bundle::LZIP, body);//命名空间bundle,支持的压缩格式有挺多的

    //向压缩文件中填写压缩好的内容
    std::ofstream ofs;
    ofs.open(ofilename, std::ios::binary);
    ofs.write(&packed[0], packed.size());

    //关闭文件描述符
    ofs.close();
    ifs.close();

    return 0;
}